import {Effect} from "../IEffectContainer";
import {ActorActionManager} from "../../manager/ActorActionManager";
import {Constant} from "../../../config/Constant";

//每秒扣血
export class zhuoshao extends Effect {
    logLevel = "zhuoshao"

    apply(target: ActorActionManager) {
        super.apply(target)
        // 每秒执行的逻辑
        this.timerId = setInterval(() => {
            this.log.log(this.logLevel, `描述:每秒灼烧[${this.damPerS}]`)
            target.hurt(this.damPerS[this.level-1],null,Constant.HURT_TYPE.Buff)
        }, 1000);

        // 5 秒后停止执行
        setTimeout(() => {
            this.log.log(this.logLevel, `${this.duration[this.level-1]/1000}秒后停止执行`)
            this.remove(target)
        }, this.duration[this.level-1]+1000);
    }

    remove(target: ActorActionManager) {
        this.log.log(this.logLevel, `提前终止`)
        let buff =target.buffs.find(b => b.effect.id == this.id);
        if(buff.timerId!=null){
            target.removeBuff(buff.effect.id)
        }
    }
}
